package com.linser.gistools.common.datastore;

import javafx.stage.FileChooser.ExtensionFilter;
import org.geotools.data.DataAccessFactory.Param;
import org.geotools.jdbc.JDBCDataStoreFactory;

/**
 * 数据库连接字段
 */
public class DatabaseConnectionField {
    //总的参数信息
    private Param param = null;

    /** The username 用户名 */
    private boolean username = false;

    /** The password 密码 */
    private boolean password = false;

    /** The is filename 是否是文件名 */
    private boolean isFilename = false;

    /** The file extension filter 文件后缀过滤 */
    private ExtensionFilter extensionFilter = null;

    /**
     * Instantiates a new database connection field 实例化新的数据库连接字段
     * @param param the param
     */
    public DatabaseConnectionField(Param param) {
        super();
        this.param = param;
        if (param.key.equals(JDBCDataStoreFactory.USER.key)) {
            username = true;
        }

        password = param.isPassword();
    }

    /**
     * Instantiates a new database connection field 实例化新的数据库连接字段
     *
     * @param param the param
     * @param extensionFilter the file extension filter 过滤
     */
    public DatabaseConnectionField(Param param, ExtensionFilter extensionFilter) {
        super();
        this.param = param;
        this.isFilename = true;
        this.extensionFilter = extensionFilter;
    }

    /**
     * Gets the field name 获取字段名称
     *
     * @return the fieldName
     */
    public String getFieldName() {
        return param.getDescription().toString();
    }

    /**
     * Checks if is optional 检查是否为可选。
     *
     * @return the optional
     */
    public boolean isOptional() {
        return !param.required;
    }

    /**
     * Checks if is username 检查是否为用户名
     *
     * @return the username
     */
    public boolean isUsername() {
        return username;
    }

    /**
     * Checks if is password. 检查是否为密码
     *
     * @return the password
     */
    public boolean isPassword() {
        return password;
    }

    /**
     * Gets the key.
     *
     * @return the key
     */
    public String getKey() {
        return param.key;
    }

    public Class<?> getType() {
        return param.getType();
    }

    /**
     * Gets the default value.
     *
     * @return the defaultValue
     */
    public Object getDefaultValue() {
        return param.getDefaultValue();
    }

    /**
     * Checks if is filename.
     *
     * @return the isFilename
     */
    public boolean isFilename() {
        return isFilename;
    }

    /**
     * Gets the file extension filter.
     *
     * @return the extensionFilter
     */
    public ExtensionFilter getFileExtensionFilter() {
        return extensionFilter;
    }
}
